package com.gluxen.service;

import java.util.HashMap;
import java.util.List;







import java.util.Map;

import javax.persistence.criteria.From;

import org.hibernate.annotations.Where;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.gluxen.dao.BaseDao;
import com.gluxen.entity.OrderForm;
import com.gluxen.entity.User;
@Service
public class OrderService extends BaseService implements IOrderService{

	@Override
	public void addOrder(OrderForm order) {
		add(order);
		
	}

	@Override
	public void deleteOrder(OrderForm order) {
		delete(order);
		
	}

	@Override
	public void updateOrder(OrderForm order) throws Exception {
		update(order);
	}

	@Override
	public List<OrderForm> queryOrder() {
		@SuppressWarnings("unchecked")
		List<OrderForm> list = (List<OrderForm>) queryAll(OrderForm.class);
		return list;
	}
	
	 //切面处理，得到日志信息
     //@MyLog(operationName = "批量删除订单", operationType = "delete")
		public void deleteOrder(String[] ids) {
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < ids.length - 1; i++)
				sb.append(ids[i] + ",");
			sb.append(ids[ids.length - 1]);
			//updateByHql("delete from UserRole ur where ur.user.id in (" + sb.toString() + ")");
			delete(OrderForm.class, sb.toString());
	}
		
		@SuppressWarnings("unchecked")
		public List<OrderForm> queryOrderByStatus(int status){
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("status", status);
			 return (List<OrderForm>) baseDao.getObjectListByMap("from OrderForm uu where uu.isDelete = 0 and uu.status=:status", paramMap);
		}

		@SuppressWarnings("unchecked")
		public List<OrderForm> queryOrderByManager(Integer manager) {
			
			/*String hql = "from User uu where uu.isDelete=0";
			hql = hql + " and uu.manager =" + manager;
			List<User> all = (List<User>)queryObjectList(hql);
			
			StringBuffer sBuffer = new StringBuffer();
			for (int i = 0; i < all.size()-1; i++)
				sBuffer.append(all.get(i).getId() + ",");
			sBuffer.append(all.get(all.size()-1).getId());
			//return (List<OrderForm>) baseDao.getObjectList("from orderForm o where o.isDelete=0 and o.user.id in ("+sBuffer.toString()+")");*/
			return (List<OrderForm>) baseDao.getObjectsByNativeSql("select * from ORDER_FORM where FK_USER_ID in(select PK_USER_ID from USER where USER.manager="+manager+")");
		}
}
